﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace UI.Control
{
    public partial class ShowNumber : UserControl
    {
        public delegate void NumberChangedHandler();
        public event NumberChangedHandler NumberChanged;

        public int CanSelectedCount { get; set; }
        List<string> Numbers = new List<string>();
        public string Value
        {
            get
            {
                return label1.Text;
            }
        }
        private string _ShowText;
        public string ShowText
        {
            get { return _ShowText; }
            set
            {
                _ShowText = value;
                label1.Text = _ShowText;
            }
        }
        public void ClearNumber()
        {
            Numbers.Clear();
            _NumberChanged();
        }
        public ShowNumber()
        {
            InitializeComponent();
        }
        public bool AddNumber(string num)
        {
            if (Numbers.Count == CanSelectedCount)
            {
                MessageBox.Show(String.Format("只能输入 {0} 个数字", CanSelectedCount));
                return false;
            }
            else
            {
                Numbers.Add(num);
                _NumberChanged();
                return true;
            }
        }
        public void RemoveNumber(string num)
        {
            Numbers.Remove(num);
            _NumberChanged();
        }
        public int NumberCount { get { return Numbers.Count; } }
        private void _NumberChanged()
        {
            if (Numbers.Count == 0)
            {
                label1.Text = _ShowText;
            }
            else
            {
                label1.Text = "";
            }
            foreach (string n in Numbers)
            {
                label1.Text += n + " ";
            }

            if (NumberChanged != null)
            {
                NumberChanged();
            }
        }
    }
}
